package com.xy.smartsms.adapter;

import android.content.Context;
import android.os.Handler;

import com.example.messageutil.iface.IMessageProcessor;
import com.example.messageutil.iface.ISmartMessageItem;
import com.example.messageutil.iface.ISmartSmsItemHolder;
import com.xy.smartsms.data.SmsItem;
import com.xy.smartsms.helper.SmartSmsCardHelper;
import com.xy.smartsms.helper.SmartSmsCardOptions;

/**
 * Created by admin on 2017/8/31 0031.
 */

public class XyMessageProcessor implements IMessageProcessor {
    private SmartSmsCardHelper mCardHelper = null;

    @Override
    public void setupProcessor(Context context, Handler handler, final ISmartSmsItemHolder holder) {
        SmartSmsCardOptions options = new SmartSmsCardOptions.Builder()
                .setContentId(holder.getContentId())
                .setRichBubbleId(holder.getRichBubbleId())
                .setSimpleBubbleId(holder.getSimpleBubbleId())
                .setRootView(holder.getRootView())
                .setParentView(holder.getParentView())
                .setCallback(new SmartSmsCardOptions.Callback() {
                    @Override
                    public void showDefaultItem(boolean hasBubble) {
                        holder.showDefaultItem(hasBubble);
                    }
                })
                .setHandler(handler)
                .build();
        mCardHelper = new SmartSmsCardHelper(context, options);
    }

    @Override
    public void bind(ISmartMessageItem item) {
        SmsItem smsItem = new SmsItem()
                .setBody(item.getSmsBody())
                .setCenter(item.getServiceCenterNum())
                .setExtend(item.getSmartSmsExtendMap())
                .setIccid(item.getICCID())
                .setMsgId(String.valueOf(item.getMsgId()))
                .setPhone(item.getPhoneNum())
                .setReceiveTime(item.getSmsReceiveTime());
        mCardHelper.bind(smsItem);
    }
}
